﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EventScavenger
{
    public partial class AddUser : Form
    {
        public AddUser()
        {
            InitializeComponent();
        }

        internal EventScavengerUser SelectedUser { get; set; }

        private void txtUsername_TextChanged(object sender, EventArgs e)
        {
            CheckOKEnabled();
        }

        private void CheckOKEnabled()
        {
            cmdOK.Enabled = (txtUsername.Text.Length > 0) &&
                            (optAdmin.Checked || optCollector.Checked || optViewer.Checked);
        }

        private void optAdmin_CheckedChanged(object sender, EventArgs e)
        {
            CheckOKEnabled();
        }

        private void optViewer_CheckedChanged(object sender, EventArgs e)
        {
            CheckOKEnabled();
        }

        private void optCollector_CheckedChanged(object sender, EventArgs e)
        {
            CheckOKEnabled();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            SelectedUser = new EventScavengerUser();
            if (optCollector.Checked)
                SelectedUser.UserType = EventScavenger.UserType.Collector;
            else if (optAdmin.Checked)
                SelectedUser.UserType = EventScavenger.UserType.Admin;
            else
                SelectedUser.UserType = EventScavenger.UserType.Viewer;
            SelectedUser.UserName = txtUsername.Text;
            DialogResult =  DialogResult.OK;
            Close();
        }
    }
}
